PowerSNMP for .NET
Marshal(String,Variable[,],String,Object) Method
Example 




The oid of the table used in SnmpSocket.GetTable.
Array of table variables to marshal to the UI thread.
Message to pass into the Table event.
Object to pass to the Table event; can be null.
Marshals an array of table variables to the UI thread.
Syntax
Public Overloads Sub Marshal( _
   ByVal oid As String, _
   ByVal table(,) As Variable, _
   ByVal message As String, _
   ByVal state As Object _
) 
Dim instance As Manager
Dim oid As String
Dim table() As Variable
Dim message As String
Dim state As Object
 
instance.Marshal(oid, table, message, state)
public void Marshal( 
   string oid,
   Variable[,] table,
   string message,
   object state
)
public: void Marshal( 
   string* oid,
   Variable*[,]* table,
   string* message,
   Object* state
) 

Parameters

oid
The oid of the table used in SnmpSocket.GetTable.
table
Array of table variables to marshal to the UI thread.
message
Message to pass into the Table event.
state
Object to pass to the Table event; can be null.
Remarks

This method can be used to marshal table information from a worker thread to the UI thread for typical display purposes. It calls the OnTable method, which raises the Table event.

See the SynchronizingObject property for information on updating UI controls in your event handler.

Example
The following example demonstrates how to retrieve a table using the GetTable method that utilizes GetBulk requests.
private void button1_Click(object sender, EventArgs e)
{
    //Start a worker thread to retrieve and display an SNMP Table
    manager1.Start(getTable, null);
}

private void getTable(SnmpSocket managerSocket, object state)
{
    //Retrieve table using GetTable with 20 max-repetitions (retrieves up to 20 rows)
    Variable[,] table = managerSocket.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, SnmpVersion.Two, "public", null, myAgentAddress, 0, 20);

    //Marshal table to UI thread
    manager1.Marshal(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, table, "", null);
}

private void manager1_Table(object sender, Dart.Snmp.TableEventArgs e)
{
    //Raised on the UI thread.
    //Populate a ListView control with the table data
    buildTable(e.Table);
}

private void buildTable(Variable[,] table)
{
    //Add columns to the ListView for each column in the table
    for (int i = 0; i < table.GetLength(1); i++)
        lvwTable.Columns.Add(table[0, i].Definition.Name, 150, HorizontalAlignment.Left);

    ListViewItem tableRow;
    int r, c = 0;
    for (r = 0; r < table.GetLength(0); r++)
    {
        //Create a new row and add the first cell
        tableRow = new ListViewItem(table[r, 0].Value.ToString());

        //Add each additional cell in the row
        for (c = 1; c < table.GetLength(1); c++)
            tableRow.SubItems.Add((table[r, c] == null) ? "NULL" : table[r, c].Value.ToString());

        //Add the row to the listview
        lvwTable.Items.Add(tableRow);
    }
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Start a worker thread to retrieve and display an SNMP Table
    manager1.Start(AddressOf getTable, Nothing)
End Sub

Private Sub getTable(ByVal managerSocket As SnmpSocket, ByVal state As Object)
    'Retrieve table using GetTable with 20 max-repetitions (retrieves up to 20 rows)
    Dim table(,) As Variable = managerSocket.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, SnmpVersion.Two, "public", Nothing, myAgentAddress, 0, 20)

    'Marshal table to UI thread
    manager1.Marshal(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, table, "", Nothing)
End Sub

Private Sub manager1_Table(ByVal sender As Object, ByVal e As Dart.Snmp.TableEventArgs)
    'Raised on the UI thread.
    'Populate a ListView control with the table data
    buildTable(e.Table)
End Sub

Private Sub buildTable(ByVal table(,) As Variable)
    'Add columns to the ListView for each column in the table
    For i As Integer = 0 To table.GetLength(1) - 1
        lvwTable.Columns.Add(table(0, i).Definition.Name, 150, HorizontalAlignment.Left)
    Next i

    Dim tableRow As ListViewItem
    Dim r As Integer, c As Integer = 0
    For r = 0 To table.GetLength(0) - 1
        'Create a new row and add the first cell
        tableRow = New ListViewItem(table(r, 0).Value.ToString())

        'Add each additional cell in the row
        For c = 1 To table.GetLength(1) - 1
            tableRow.SubItems.Add(If(table(r, c) Is Nothing, "NULL", table(r, c).Value.ToString()))
        Next c

        'Add the row to the listview
        lvwTable.Items.Add(tableRow)
    Next r
End Sub
See Also

Reference

Manager Class
Manager Members
Overload List


PowerSNMP for .NET Documentation Version 8.0
© 2024 Dart Communications. All Rights Reserved.
Send comments on this topic